﻿using System;
using System.Collections.Generic;
using System.Text;

namespace oceanho.webapi.factory.httpAttr
{
    /// <summary>
    /// 定义一个Attribute，用于指示该方法的调用路由规则,例如（userApi/addPassword）
    /// </summary>
    [AttributeUsage(AttributeTargets.Method, Inherited = true, AllowMultiple = false)]
    public class RouterAttribute : Attribute
    {
        /// <summary>
        /// 指示该方法的调用路由规则
        /// </summary>
        public RouterAttribute()
            : this(null)
        {
        }

        /// <summary>
        /// 指示该方法的调用路由规则
        /// </summary>
        /// <param name="route"></param>
        public RouterAttribute(string route)
        {
            this.Route = route;
        }

        private string _route = string.Empty;

        /// <summary>
        /// 获取或者设置一个值，该值表示该方法的调用路由规则
        /// </summary>
        public string Route
        {
            get
            {
                return this._route;
            }
            set
            {
                this._route = value;
                if (this._route != string.Empty)
                {
                    this._route = this._route.TrimStart('/').TrimEnd('/');
                }
            }
        }
    }
}
